package com.ylsd.prospectivestudent.utils;


import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.ylsd.prospectivestudent.entity.PSExcelModel;
import com.ylsd.prospectivestudent.entity.ImportStudents;
import com.ylsd.prospectivestudent.service.PSService;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Component
@Data
@AllArgsConstructor
@NoArgsConstructor
public class EdustudentListener extends AnalysisEventListener<ImportStudents> {

    List<ImportStudents> studentList = new ArrayList<ImportStudents>();

    @Resource
    private PSService psService;

    @Override
    public void invoke(ImportStudents data, AnalysisContext context) {
        //System.out.println(data.toString());
        studentList.add(data);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        psService.importStudents(studentList);
        studentList.clear();
    }
}
